<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Send Email</title>
</head>
<body>
<form id="mailForm">
    发送人邮箱：<input type="text" name="from" id="from"/><br/>
    收件人邮箱：<input type="text" name="to" id="to"/><br/>
    抄送人邮箱：<input type="text" name="cc" id="cc"/><br/>
    邮箱的主题：<input type="text" name="subject" id="subject"/><br/>
    邮箱的内容：<textarea rows="10" cols="40" name="content" id="content"></textarea><br/>
    <button type="button" onclick="sendEmail()">发送邮件</button>
</form>

<script>
    function sendEmail() {
        const mail = {
            from: document.getElementById('from').value,
            to: document.getElementById('to').value,
            cc: document.getElementById('cc').value,
            subject: document.getElementById('subject').value,
            content: document.getElementById('content').value,
            attachFileNames: []
        };

        fetch('http://localhost:8081/sendSimpleMail', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(mail)
        })
            .then(response => {
                if (response.ok) {
                    return response.text();
                } else {
                    throw new Error('Network response was not ok.');
                }
            })
            .then(data => {
                alert('邮件发送成功！');
            })
            .catch(error => {
                console.error('There was a problem with your fetch operation:', error);
                alert('邮件发送失败，请重试。');
            });
    }
</script>
</body>
</html>
